package service;

import communication.ParameterizedMessage;
import communication.ParameterizedMessageImpl;

public class StopServiceRequestHandler extends ServiceRequestHandler {

	public StopServiceRequestHandler(AbstractService service) {
		super("ServiceControl:StopService", service);
	}

	@Override
	public ParameterizedMessage handle(ParameterizedMessage message) {
		
		ParameterizedMessage msg = new ParameterizedMessageImpl("StopServiceResult");
		
		try {
			getService().close(message);
			
			getService().markAsClosed();
			
			msg.setParameter("result", "success");
		} catch (Exception e) {
			msg.setParameter("result", "failed");
			msg.setAttachment(e);
		}
		
		return msg;
	}

}
